import UIKit

class ViewController4: UIViewController {
    
    let image1 = UIImage(named: "bg1")!
    let image2 = UIImage(named: "templateBack")!
    let image3 = UIImage(named: "templateFont")!
    
    let image = UIImage(named: "demoImg.jpg")!

    lazy var templateEditContainer: TemplateEditContainer4 = {
        let w : CGFloat = 763
        let h : CGFloat = 1021
        let frames = [CGRect(x: 284, y: 835, width: w, height: h)]
        let info = TemplateInfo(bgImage: image1,templateBackImage: image2, templateFontImage: image3, imageFrames: frames)
        let v = TemplateEditContainer4(info)
        v.clipsToBounds = true
        v.onAddImage = {[weak self] index in
            if let self = self {
                v.setImage(index: index, image: self.image)
            }
        }
        return v
    }()
    

    override func viewDidLoad() {
        super.viewDidLoad()
        createSubview()
    
    }
    
    // Methods
    func createSubview() {
        view.backgroundColor = .white
        view.addSubview(templateEditContainer)
        templateEditContainer.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        DispatchQueue.main.asyncAfter(deadline: .now() + 3){

            let w = UIScreen.main.bounds.width - 100
            self.templateEditContainer.snp.remakeConstraints { make in
                //            make.edges.equalToSuperview()
                make.center.equalToSuperview()
                make.width.equalTo(w)
                make.height.equalTo(w / 0.51)
            }
            DispatchQueue.main.asyncAfter(deadline: .now() + 2){
                self.templateEditContainer.snp.makeConstraints { make in
                    make.edges.equalToSuperview()
                }
            }
        }
//
//        let w = UIScreen.main.bounds.width - 100
//        self.templateEditContainer.snp.remakeConstraints { make in
//            //            make.edges.equalToSuperview()
//            make.center.equalToSuperview()
//            make.width.equalTo(w)
//            make.height.equalTo(w / 0.56)
////            make.height.equalTo(w / 0.46)
////            make.height.equalTo(w / 0.40)
//        }
    }
}
